<!--
- File:    退货用户寄出的物流信息.
-->
<template>
  <div class="p20 apply_box bg_fff">
    <p>物流公司 </p>
    <div class="apply_sel"><i class="iconfont icon-downdot2"></i>
      <select v-model="selectedExpressId">
        <option value="" selected>请选择物流公司</option>
        <option :value="item.id" v-for="item in expressList">{{item.e_name}}</option>
      </select>
    </div>
    <p>物流单号</p>
    <div class="apply_sel"><input type="text" v-model="expressCode"></div>
    <div class="apply_sel2">
      <button @click="addRefundExpress" v-show="!expressInfo.info.invoice_no">提交申请</button>
    </div>
    <back-nav></back-nav>
  </div>
</template>

<script>
  import * as request from '../../../request'
  import {mapModules, mapRules} from 'vuet'

  export default{
    beforeRouteEnter (to, from, next) {
      request.getRefundExpress(to.query.refundId).then(data => {
        next(vm => {
          vm.expressInfo = data
          if (data.express && data.express.id) {
            vm.selectedExpressId = data.express.id
          }
          if (data.info.invoice_no) {
            vm.expressCode = data.info.invoice_no
          }
        })
      }).catch(e => {
        next()
      })
    },
    mixins: [
      mapModules({expressList: 'expressList'}),
      mapRules({once: 'expressList'})
    ],
    data() {
      return {
        refundId: this.$route.query.refundId,
        expressInfo: {address: {}, express: null, info: {}},
        selectedExpressId: '',
        expressCode: ''
      }
    },
    created() {
    },
    methods: {
      addRefundExpress() {
        if (this.selectedExpressId == '') {
          this.$toast('请选择物流公司')
          return
        }
        if (this.expressCode == '') {
          this.$toast('请输入物流单号')
          return
        }
        let param = {refund_id: this.refundId, express_id: this.selectedExpressId, express_code: this.expressCode}
        this.$request.addRefundExpress(param).then(data => {
          this.$toast('添加物流信息成功')
          this.$router.go(-1)
        }).catch(e => {
          this.$toast('添加物流信息失败：' + e.msg)
        })
      }
    }
  }
</script>

<style>

</style>